/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 *
 */

import { findTargetProduct } from '../common/find-target-product.js';
import { CommonConst } from '../const/common-const.js';
import { RuntimeTypeEnum } from '../enum/runtime-type-enum.js';
import { ProjectModel } from '../model/project/project-model.js';
import { ProjectBuildProfile } from '../options/build/project-build-profile.js';

/**
 * 提供一个单例对象，来初始化工程的所有模块的额外的状态信息，并在执行任务时获取
 *
 * @since 2022/1/18
 */
export class ProjectExtraInfoService {
  static getProjectRuntimeOS(project: ProjectModel): RuntimeTypeEnum {
    const productOpt: ProjectBuildProfile.ProductBuildOpt = findTargetProduct(project);
    if (productOpt.runtimeOS) {
      return RuntimeTypeEnum.valueOf(productOpt.runtimeOS);
    }
    if (productOpt.compatibleSdkVersion && typeof productOpt.compatibleSdkVersion === 'number') {
      return RuntimeTypeEnum.valueOf(CommonConst.OPEN_HARMONY);
    }
    return RuntimeTypeEnum.valueOf(CommonConst.HARMONY_OS);
  }
}
